package com.negative.logic;

import java.io.Serializable;
import java.util.Date;

@SuppressWarnings("serial")
public class FilterEventByDate implements Serializable{
	
	private Date startDate;
	public Date getStartDate() {
		return startDate;
	}


	public Date getEndDate() {
		return endDate;
	}

	private Date endDate;

	public FilterEventByDate()
	{
		this.startDate = null;
		this.endDate = null;
	}
	
	
	public FilterEventByDate(Date start, Date end) {
		if(start == null)
		{
			start = new Date();
		}
		this.startDate = start;
		if(end != null && start.after(end) == true)
		{
			this.endDate = null;
		}
		else
		{
			this.endDate = end;
		}
	}
	
	public boolean isFilteredEvent(Date eventDate) {

		if(eventDate == null)
		{
			return false;
		}
		if(isBeforeStartDate(eventDate) == true)
		{
			return true;
		}
		if(isAfterEndDate(eventDate) == true)
		{
			return true;
		}
		return false;
	}

	private boolean isBeforeStartDate(Date eventDate)
	{
		if(startDate == null)
		{
			return false;
		}
		if(startDate.getYear() > eventDate.getYear())
		{
			return true;
		}
		if(startDate.getYear() == eventDate.getYear() &&
			startDate.getMonth() > eventDate.getMonth())
		{
			return true;
		}
		if(startDate.getYear() == eventDate.getYear() &&
			startDate.getMonth() == eventDate.getMonth() &&
			startDate.getDate() > eventDate.getDate())
		{
			return true;
		}
		return false;
	}
	
	private boolean isAfterEndDate(Date eventDate)
	{
		if(endDate == null)
		{
			return false;
		}
		if(endDate.getYear() < eventDate.getYear())
		{
			return true;
		}
		if(endDate.getYear() == eventDate.getYear() &&
			endDate.getMonth() < eventDate.getMonth())
		{
			return true;
		}
		if(endDate.getYear() == eventDate.getYear() &&
			endDate.getMonth() == eventDate.getMonth() &&
			endDate.getDate() < eventDate.getDate())
		{
			return true;
		}
		return false;
	}
}
